{extend name="public:base" /}

{block name="jquery"}
<script src="__PUBLIC__/jquery-weui/dist/lib/jquery-2.1.4.js"></script>
{/block}  

{block name="head"}
<link href="__PUBLIC__/view_res/mobile/css/cart.css" type="text/css" rel="Stylesheet" />
<link href="__PUBLIC__/jquery-weui/dist/lib/weui.min.css" type="text/css" rel="Stylesheet" />
<link href="__PUBLIC__/jquery-weui/dist/css/jquery-weui.min.css" type="text/css" rel="Stylesheet" />
<script src="__PUBLIC__/jquery-weui/dist/lib/fastclick.js"></script>
<script src="__PUBLIC__/jquery-weui/dist/js/jquery-weui.min.js"></script>
<script src="__PUBLIC__/jquery-weui/dist/js/city-picker.js"></script>
<script src="__PUBLIC__/js/jquery/jquery-migrate-1.2.1.min.js"></script>
<script src="__PUBLIC__/artTemplate/template.js"></script>
<script src="__PUBLIC__/view_res/mobile/load_list.js"></script>
{/block} 
{block name="header"}
{include file="public/top-nav" /}
{/block}

{block name="content"}

<input type="hidden" id="weight" value="0" />
<input type="hidden" id="shipping" value="{$shipping|default=''}" />{//是否需要配送}
<input type="hidden" id="city_id" value="{$address.city_id|default=''}" />{//配送的城市}
<input type="hidden" id="address_id" value="{$address.address_id|default=''}" />{//配送的地址}
<input type="hidden" id="agent_id" value="{$goods.agent_id|default=''}" />{//供货商}

<!-- 收货地址 start -->
{if condition="!empty($goods)"}
	
		<div id="shipping_box">
			<div id="addrPick"></div>
			<header class="Thead">收货信息</header>
			<div id="express-bar"></div>
			<div id="express_address">	
			{if condition="isset($address)"}   
			<div class="express-person-info clearfix">
			    <div class="express-person-name">
			        <span id="express-name">{$address.name|default=''}</span><span id="express-person-phone">{$address.telephone|default=''}</span>
			    </div>
			</div>
			<div class="express-address-info">
			    <span  id="express-address">{$address.address|default=''}</span>
			</div>
			{else/}
				<div id="wrp-btn">点击选择收货地址</div>
				<div class="express-person-info clearfix">
			    <div class="express-person-name">
			        <span id="express-name"></span><span id="express-person-phone"></span>
			    </div>
			</div>
			<div class="express-address-info">
			    <span id="express-address"></span>
			</div>
			{/if}
			</div>
		</div>
	
{/if}	
<!-- 收货地址 end -->

<header class="Thead">订单信息</header>

<div id="orderDetailsWrapper" data-minheight="68px">
	
	{if condition="!empty($goods)"}

		<section class="cartListWrap clearfix" id="goods">
		
	    <a href="{:url('points/detail',array('id'=>$goods['goods_id']))}">
	    	<img alt="{$goods.name}"  src="IMG_ROOT{$goods.image|resize=80}" />
	    </a>
	    
	    <div class="cartListDesc">
	        <p class="title">
	            <a style="color:#000;" href="{:url('points/detail',array('id'=>$goods['goods_id']))}">{$goods.name}</a>
	        </p>
	        <p class="count">
	        	{if condition="$goods['shipping'] eq 0"}
	        	<span class="spec Elipsis" style="border:1px solid #f60;color:#f60;">免配送</span><br />
	        	{/if}
	            <span class="spec Elipsis">	              
	                {volist name="$option" id="o"}	
					<small>{$o.name}:{$o.value}</small><br />
					{/volist}					
	            </span>	            
					<span class="dprice prices">银豆：{:get_attribute_money($cart.goods_id,$cart.attribute_value_id)}</span>
	        </p>
			<p>
				<span class="dprice prices">规格：{:get_value_name($cart.attribute_value_id)}</span>
			</p>
	     
	    </div>
		</section>

	{else/}
			<div id="cartnothing" onclick="location='{:url("points/index")}'">购物车空空如也，去逛逛吧</div>
	{/if}
</div>



{if condition="!empty($goods)"}		
	<section class="orderopt inp" id="beizhu">
        <span class="label">订单备注</span>
        <input type="text" class="Elipsis" value="" id="comment" name="comment" id="input-remark" placeholder="选填，可填写您的特殊要求" />
    </section>	
		
    <!-- 订单总额 -->
    <div id="orderSummay">	       
        <div>
            总计 : <b class="prices"> </b> <b class="prices last" id="order_points_amount">{:get_attribute_money($cart.goods_id,$cart.attribute_value_id)} 银豆</b>
        </div>            
    </div>
  
	<div class="weui_btn_area">
	   <a class="weui_btn weui_btn_primary payment" id="points-payment-btn">立即购买</a>
	</div>       
{/if}

{//*************手机版 收货地址  START  *************}

{include file="cart/address" /}

{//*************手机版 END  *************}


{/block}

{block name="script"}
<script>
<?php if(isset($error)){ ?>
	$.toast.prototype.defaults.duration='4000';
	$.toast('<?php echo $error; ?>', "forbidden");
<?php } ?>


//积分兑换
$('#points-payment-btn').click(function(){
	
	var city_id=$('#city_id').val();
	var address_id=$('#address_id').val();
	var comment=$('#comment').val();
	var agent_id=$('#agent_id').val();

	$.ajax({
		url: '{:url("points/payment")}',
		type: 'post',	
		data:{
			id:'{:input("param.id")}',
			city_id:city_id,
			comment:comment,
			address_id:address_id,
			agent_id:agent_id
		},
		beforeSend: function() {
			$('#points-payment-btn').attr('disabled', true);			
			$.showLoading();
		},	
		complete: function() {
			$('#points-payment-btn').attr('disabled', false); 
     		$.hideLoading();
		},			
		success: function(d) {
			if(d.error){				
				$.toast(d.error, "forbidden");				
			}			
			if(d.success){	
				
				setTimeout(function (){				  		
			      $.toast('兑换成功');	
			    }, 1000);
									
				setTimeout(function (){				  		
			      location=d.success; 
			    }, 2000);
			}			
		},
		error: function(xhr, ajaxOptions, thrownError) {
			$('#points-payment-btn').attr('disabled', true);
			alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
		}
	});
	
});

</script>

{/block}


